<?php
/**
 * Created by PhpStorm.
 * User: user1
 * Date: 2018/9/3
 * Time: 11:05
 */

namespace app\admin\controller;


use app\common\service\JurisdictionService;
use app\common\tool\Tool;
use think\Controller;
use think\Exception;
use think\facade\Request;

class Common extends Controller
{

    use Tool;

// 前置操作
    protected $beforeActionList = [
        'before_action',
    ];

    /**
     *  通过前置操作检查权限，登录状态等等
     * @throws Exception
     */
    protected function before_action()
    {
        $admin  = session('szb_admin');
        if (!$admin) {
            throw new Exception('no_login');
        }
//echo Request::module() . Request::controller() . Request::action();exit;
        try {
            // 验证登录权限
            JurisdictionService::checkAdminLoginJurisdiction($admin);

            // 返回管理员数据
            $this->assign('admin', $admin);

        } catch (Exception $e) {
            if (Request::isAjax()) {
                $this->jurisdiction_error($e->getMessage());
            } else {
                $this->redirect('base/error_page', ['msg' => $e->getMessage()]);
            }
        }
    }
}